package org.acghub.common.topology;

import java.util.Comparator;
import java.util.List;

/**
 * @Project demos
 * @Package org.acghub.common.topology
 * @Desc
 * @Author Administrator
 * @Date 2025/7/16/星期三 19:31
 * @Version 1.0
 */
public interface TopologyGraph<T> extends CircleFinder<T> {

    /**
     * 添加孤立节点
     *
     * @param node
     */
    void addIsolatedNode(T node);

    /**
     * 移除孤立节点
     *
     * @param node
     * @return
     */
    boolean removeIsolatedNode(T node);

    /**
     * 获取拓扑排序队列
     *
     * @param comparator
     * @return
     */
    List<T> topologyQueue(Comparator<T> comparator);

    /**
     * 拓扑排序遍历
     *
     * @param walkable
     */
    void walk(TopologyWalkable<T> walkable, Comparator<T> walkComparator);

    /**
     * 获取指定度数的节点
     *
     * @param degreeType
     * @param degree
     * @return
     */
    List<T> getNodes(DegreeType degreeType, int degree);

    /**
     * 获取节点的邻居
     *
     * @param node
     * @return
     */
    List<T> getNeighbors(T node);

    /**
     * 获取指定度数的邻居
     *
     * @param node
     * @param degreeType
     * @param degree
     * @return
     */
    List<T> getNeighbors(T node, DegreeType degreeType, int degree);

    default List<T> topologyQueue() {
        return topologyQueue(null);
    }

    default void walk(TopologyWalkable<T> walkable) {
        walk(walkable, null);
    }

    enum DegreeType {

        IN(1),

        OUT(2),

        ;

        private final int value;

        DegreeType(int value) {
            this.value = value;
        }

        public int value() {
            return value;
        }
    }

    interface TopologyWalkable<T> {
        void walk(T node, T father);
    }
}
